import jsonp from 'common/js/jsonp'
import { commonParams, options } from './config'
import Axios from 'axios'

export function getHotKey () {
  const url = 'https://c.y.qq.com/splcloud/fcgi-bin/gethotkey.fcg'
  const params = Object.assign({}, commonParams, {
    _: new Date().getTime(),
    g_tk: 751394570,
    uin: 0,
    notice: 0,
    platform: 'h5',
    needNewCode: 1
  })
  return jsonp(url, params, options)
}

export function search (query, page, zhida, perpage) {
  const url = '/api/search'
  const data = Object.assign({}, commonParams, {
    w: query,
    p: page,
    catZhida: zhida ? 1 : 0,
    zhidaqu: 1,
    _: new Date().getTime(),
    g_tk: 5381,
    uin: 0,
    notice: 0,
    platform: 'h5',
    needNewCode: 1,
    flag: 1,
    ie: 'utf-8',
    sem: 1,
    aggr: 0,
    perpage,
    n: 20,
    remoteplace: 'txt.mqq.all'
  })
  return Axios.get(url, {
    params: data
  }).then(resp => {
    return Promise.resolve(resp.data)
  })
}
